package com.qu.ListControl.materialdesign.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qu.ListControl.List.base.BaseRecyclerAdapter;
import com.qu.ListControl.R;
import com.qu.ListControl.materialdesign.adapter.Test1Adapter;
import com.qu.ListControl.materialdesign.bean.Test1;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Test1Fragment extends Fragment {
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    private Test1Adapter adapter;
    public static Test1Fragment newInstance() {
        Test1Fragment fragment = new Test1Fragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_test1, container, false);
        ButterKnife.bind(this,view);
        initDada();
        return view;
    }

    private void initDada() {
        adapter = new Test1Adapter(getActivity(), BaseRecyclerAdapter.ONLY_FOOTER);
        LinearLayoutManager linearlayout = new LinearLayoutManager(getActivity());
        recyclerview.setLayoutManager(linearlayout);
        recyclerview.setAdapter(adapter);
        if(adapter.getItems().size() == 0){
            adapter.addAll(getData());
        }
    }

    //制作假数据
    public List<Test1> getData(){
        List<Test1> list = new ArrayList<>();
        for(int i = 0;i<20;i++){
            Test1 text = new Test1();
            text.setText("design库的控件的测试_"+i);
            list.add(text);
        }
        return list;
    }
}
